<template>
    <el-row class="resMan">
        <el-row type="flex" style="height: 40px;margin-bottom: 14px;position: relative">
<!--            <el-input placeholder="请输入内容" style="width: 300px;margin-right: 20px;"></el-input>-->
<!--            <el-button type="primary" style="width: 100px;">搜索</el-button>-->
            <el-button type="primary" @click="addRes" style="width: 100px;position: absolute;right: 0;">新增资源</el-button>
        </el-row>
        <el-table
                :data="resourceData"
                style="font-size: 16px;"
                size="mini"
                height="730"
                max-height="730"
                @current-change="resChge"
                :header-cell-style="{background:'#e5ecf1',fontWeight: 'bold',textAlign: 'center'}"
                highlight-current-row
                border

        >
            <el-table-column fixed prop="code" label="编码" min-width="200"></el-table-column>
            <el-table-column prop="name" label="名称" min-width="200"></el-table-column>
            <el-table-column prop="url" label="链接" min-width="200"></el-table-column>
            <el-table-column fixed="right" width="100" label="操作">
                <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="editRes(scope.row)" style="font-size: 16px;">修改
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-row type="flex" justify="center" class="pagination">
            <el-pagination
                    @size-change="resurceSizechge"
                    @current-change="pgChge"
                    :current-page="resourcePage.currentPage"
                    :page-sizes="[10, 20, 30]"
                    :page-size="resourcePage.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="resourcePage.totalElements"
            ></el-pagination>
        </el-row>
        <transition name="el-fade-in">
            <floatingBox v-show="editBoxShow">
                <addRes v-if="addShow" slot="edit" @editState="editState"></addRes>
                <editRes v-if="editShow" slot="edit" :resUuid="uuid" @editState="editState"></editRes>
            </floatingBox>
        </transition>
    </el-row>
</template>

<script>
    import {getDataForSP, writePageInfo} from "../../../utils/webUtils.js";
    import floatingBox from "../../public/floatingBox.vue";
    import editRes from "./editRes.vue";
    import addRes from "./addRes.vue";

    export default {
        name: "resMan",
        components: {addRes, editRes, floatingBox},
        data() {
            return {
                formAlignLeft: 'left',
                editBoxShow: false,
                addShow: false,
                editShow: false,
                resEdit: false,
                uuid: '',
                resourceData: [],
                resourcePage: {
                    pageSize: 10,//每页显示条目个数
                    currentPage: 1,//当前页数
                    totalElements: 0,
                    searchData: {}
                }
            };
        },
        mounted() {
            this.queryResource();
        },
        methods: {
            editState(msg) {
                this.editBoxShow = msg;
                this.editShow = msg;
                this.addShow = msg;
                this.resEdit = msg;
                this.queryResource();
            },
            addRes() {
                this.editBoxShow = true;
                this.addShow = true;
            },
            editRes(val) {
                this.uuid = val.uuid;
                this.editBoxShow = true;
                this.editShow = true;
                this.resEdit = true;
            },
            resChge( val ) {
                if ( this.resEdit ) {
                    this.uuid = val.uuid;
                }
            },
            //获取所有资源
            queryResource() {
                this.axios
                    .request({
                        method: "get",
                        url: "./kwp/kdi/res/search/findAll",
                        params: getDataForSP(this.resourcePage)
                    })
                    .then(response => {
                        this.resourceData = response.data.content;
                        writePageInfo(this.resourcePage, response.data);
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },
            resurceSizechge: function (pageSize) {
                this.resourcePage.pageSize = pageSize;
                if (this.resourcePage.currentPage === 1) {
                    this.queryResource();
                }
                this.resourcePage.currentPage = 1;
            },
            pgChge(currentPage) {
                this.resourcePage.currentPage = currentPage;
                this.queryResource();
            }
        }
    }
</script>

<style scoped>
    .resMan {
        margin-right: 30px;
    }


</style>